/**
 * Created by Administrator on 2020/5/14.
 */
;
var db = require("../../javascript/mysql");
var mysql = new db.mysqlClient("accident");
var years = ["0-9", "10-17", "18-24", "25-29", "30-39", "40-44", "45-49", "50-54", "55-59", "60-64"];
function genProductInfo() {
    for (i = 0; i < years.length; i++) {
        data = {
            "year": years[i],
            "days": "1y",
            "people_count": "1",
            "serious_disable": "30000",
            "accident_disable": "300000",
            "accident_medical": "30000",
            "airplane_death": "300000",
            "train_death": "200000",
            "ship_death": "100000",
            "common_traffic": "50000"
        };


        days = Number(data.year.split("-")["0"]);

        //计算保费
        CalculationFee(days, 0);

        df = Object.assign(result, data);
        mysql.insertData(df)


    }

    for (i = 0; i < years.length; i++) {
        data = {
            "year": years[i],
            "people_count": "1",
            "serious_disable": "50000",
            "accident_disable": "500000",
            "accident_medical": "50000",
            "airplane_death": "500000",
            "train_death": "300000",
            "ship_death": "200000",
            "common_traffic": "100000"
        };

        days = Number(data.year.split("-")["0"]);

        //计算保费
        CalculationFee(days, 1);

        df = Object.assign(result, data);
        mysql.insertData(df)
    }
    for (i = 0; i < years.length; i++) {
        data = {
            "year": years[i],
            "days": "1y",
            "people_count": "1",
            "serious_disable": "100000",
            "accident_disable": "1000000",
            "accident_medical": "100000",
            "airplane_death": "1000000",
            "train_death": "600000",
            "ship_death": "400000",
            "common_traffic": "200000"
        };

        days = Number(data.year.split("-")["0"]);

        //计算保费
        CalculationFee(days, 2);

        df = Object.assign(result, data);
        mysql.insertData(df)
    }


}
function CalculationFee(day, plan) {

    var list = [
        {
            '0-9': [188],
            '1-9': [188],
            '2-9': [188],
            '3-9': [188],
            '4-9': [188],
            '5-9': [188],
            '6-9': [188],
            '10-17': [192],
            '18-24': [496],
            '25-29': [509],
            '30-39': [543],
            '40-44': [577],
            '45-49': [647],
            '50-54': [762],
            '55-59': [929],
            '60-64': [1156]
        },
        {
            '0-9': [314],
            '1-9': [314],
            '2-9': [314],
            '3-9': [314],
            '4-9': [314],
            '5-9': [314],
            '6-9': [314],
            '10-17': [320],
            '18-24': [827],
            '25-29': [848],
            '30-39': [905],
            '40-44': [962],
            '45-49': [1079],
            '50-54': [1271],
            '55-59': [1550],
            '60-64': [1928]
        },
        {
            '0-9': [628],
            '1-9': [628],
            '2-9': [628],
            '3-9': [628],
            '4-9': [628],
            '5-9': [628],
            '6-9': [628],
            '10-17': [641],
            '18-24': [1655],
            '25-29': [1697],
            '30-39': [1810],
            '40-44': [1924],
            '45-49': [2159],
            '50-54': [2541],
            '55-59': [3100],
            '60-64': [3856]
        }
    ];
    for (var key in list[plan]) {
        var keySplit = key.split("-");
        if (day >= keySplit[0] && day <= keySplit[1]) {

            price = (parseInt(list[plan][key]).toFixed(2));
            result = {
                "name": "一生安康家庭保障计划",
                "company": "中国人民保险",
                "price": price
            };

            return result;

        }
    }


}
